-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: Wrap or remove deprecated functions #760
Conversation
tests/test_config.py
Outdated
return cp | ||
|
||
def update_config(*args, **kwargs): | ||
# For testing purposes it's easiest to use the deprecated functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
# For testing purposes it's easiest to use the deprecated functions | |
# For testing purposes it's easier to use the deprecated functions |
tests/test_config.py
Outdated
@@ -29,10 +28,22 @@ def autouse_config_tmpdir(config_tmpdir): | |||
|
|||
def cfg(f=ALL, topdir=None): | |||
# Load a fresh configuration object at the given level, and return it. | |||
cp = configparser.ConfigParser(allow_no_value=True) | |||
config.read_config(configfile=f, config=cp, topdir=topdir) | |||
cp = config.configparser.ConfigParser(allow_no_value=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly not your fault but this commit is incredibly hard to review... first, this import rename is horrible because it hides both the origin and nature of config
:
from west import configuration as config
(don't change it now because it would have a massive ripple effect)
Then, I can't find west.configuration.configparser
in the documentation. Is this is some "private" object (ab)used for "white box" testing? If yes please add a comment stating that. If not, sorry I missed what it is.
The icing on the cake is the fact that this commit replaces Python's built-in configparser
with west.configuration.configparser
which has the very same name while being a bit of a mystery...
I hate to ask but... could you slow down a little bit? Maybe move this to a separate commit. Either way, provide a bit more comments, commit message, etc. Thanks in advance!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was contemplating the same things, but tried to touch it "minimally" I'll try to clean this up so that it makes sense what is builtin and what not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted to the original configparser
.
tests/test_config.py
Outdated
# For testing purposes it's easiest to use the deprecated functions | ||
# but make these calls explicit. | ||
with pytest.deprecated_call(): | ||
return config.update_config(*args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
@@ -1631,7 +1630,6 @@ def test_init_local_with_manifest_filename(repos_tmpdir): | |||
# success | |||
cmd(['init', '--mf', 'project.yml', '-l', zephyr_install_dir]) | |||
workspace.chdir() | |||
config.read_config() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a separate commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a separate commit.
tox.ini
Outdated
@@ -37,6 +37,6 @@ setenv = | |||
# For instance: ./.tox/py3/tmp/ | |||
TOXTEMPDIR={envtmpdir} | |||
commands = | |||
python -m pytest --cov-report=html --cov=west {posargs:tests} --basetemp='{envtmpdir}/pytest with space/' | |||
python -m pytest -W error --cov-report=html --cov=west {posargs:tests} --basetemp='{envtmpdir}/pytest with space/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, but could there be a convenient way/setting to temporarily turn this off? I mean without git diff
and git status
pollution.
When hacking, there is often a intermediate stage where you really want the tests to pass on work in progress that still has warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed it from the tox.ini
file and added it to the CI run.
tests/test_config.py
Outdated
with pytest.deprecated_call(): | ||
return config.update_config(*args, **kwargs) | ||
|
||
def delete_config(*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning: this review comment will be hard to find because that line is changed in a later commit in the PR and Github doesn't like the multi-commit, force-push workflow.
There is already an API named delete_config()
, I know because it shows up in a later commit! So please use a different name for internal symbols. Example:
def delete_config(*args, **kwargs): | |
def delete_testcfg(*args, **kwargs): |
Same for update_config
above.
Sincere condolences for the ripple effect on consecutive commits :-(
Generally speaking, please choose less "API-looking" names for internal symbols. Pretty much everything here is called something_config
and it's incredibly hard to keep track of what is: 1) Builtin Python (e.g. configparser
) 2) deprecated west API 3) current west API 4) private west objects abused for "white box" testing 5) local/private test symbols,....
It's never going to be perfect and please avoid unnecessary git churn when possible, but brand new symbols like this one is where progress can and should be made.
This is a cleanup PR so it should bring more clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried to do it in some reasonable steps, but I think it can make it harder to follow.
I'll come back to this PR, but there's no urgency here, as I didn't intend on getting into 1.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed as suggested, which is clearer.
These calls are deprecated and unneeded, simply remove them. Signed-off-by: Pieter De Gendt <[email protected]>
d450aad
to
6aa9f89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great except for one confusing, one-line change.
tests/test_config.py
Outdated
@@ -30,9 +32,21 @@ def autouse_config_tmpdir(config_tmpdir): | |||
def cfg(f=ALL, topdir=None): | |||
# Load a fresh configuration object at the given level, and return it. | |||
cp = configparser.ConfigParser(allow_no_value=True) | |||
config.read_config(configfile=f, config=cp, topdir=topdir) | |||
cp.read(config._gather_configs(f, topdir), encoding='utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After searching the code, I found that _gather_configs()
is just an internal implementation detail of read_config()
and used only by that deprecated function. This means _gather_configs()
is effectively deprecated too. So I don't see what this particular line change brings except some confusion, sorry.
I think you should either "upgrade" this function to the newer API if possible, or not change it at all yet if not possible and/or too much work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've wrapped the call in with pytest.deprecated_call()
as it requires a lot more work in this case. Also added a TODO
comment.
Make deprecated calls explicit during testing or remove them if unnecessary. Change the update_config and delete_config helper methods to use a Configuration class instead of the global deprecated config functions. Signed-off-by: Pieter De Gendt <[email protected]>
The deprecated delete_config function supports passing a list of ConfigFile enumerations. Update argument typing accordingly. Signed-off-by: Pieter De Gendt <[email protected]>
Don't allow warnings during CI testing. Signed-off-by: Pieter De Gendt <[email protected]>
6aa9f89
to
21a4d02
Compare
Make deprecated calls explicit during testing or remove them if unnecessary.
This allows us to promote warnings to errors with
pytest
.